	title    "BIN2BCD" ;*-------------------------------*
;*					 	                                *
;*   Convert the Binary (8-bit) value of WREG register  *
;*   to BCD value and to ASCII value.                   *
;*------------------------------------------------------*
	list      p=18f452
	#include <p18f452.inc>
;
	GLOBAL   BIN2BCD, UBCD, HBCD, LBCD, UASCI, HASCI, LASCI
;
varable     UDATA
; - - - - - - - - -
UBCD		res 1		;Upper BCD 		
HBCD		res 1		;High  BCD
LBCD		res 1  		;Low   BCD
UASCI		res 1		;Upper ASCI		
HASCI		res 1		;High  ASCI
LASCI		res 1  		;Low   ASCI
;
	    CODE
BIN2BCD
;.............
	movwf   LBCD
	clrf    HBCD	
	clrf    UBCD	
G100	
	movlw	.100
	subwf	LBCD,W		;LBCD-100
	btfss	STATUS,C	;is value greater then 100
	bra		G10		    ;NO
	movwf	LBCD		;subtraction result
	incf	UBCD,F		;UBCD++
	bra		G100
G10
	movlw	.10
	subwf	LBCD,W		;LBCD-10
	btfss	STATUS,C	;is value greater then 10
	bra		G1  		;NO
	movwf	LBCD
	incf	HBCD,F		;HBCD++
	bra		G10
G1						;end of conversion
	movlw   0x30		;convert BCD to ASCII digit
	iorwf   UBCD,W
    movwf   UASCI
	movlw   0x30
	iorwf   HBCD,W
    movwf   HASCI
	movlw   0x30
	iorwf   LBCD,W
    movwf   LASCI
	return
;*********************************************************************
	end
